<?php
/**
 * @file $HeadURL: sns_myprofile.php $
 * @author $Author: LiangJian (liangjian@haibao.com) $
 * @date $Date: 2015-4-2 下午2:12:27 $
 * @brief 
 */
namespace haibao\user\data;

class SnsMyProfile extends \haibao\user\data\BaseMysql{

	public function __construct(){
		parent::__construct('\haibao\user\model\data\SnsMyProfile');
		$this->setConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_DZ3);
	}

	public function getProfileByUserId($userId){
// 		$sql = "select * from `sns_myprofile` where user_id=%s limit 1";
		$sql = 'SELECT a.*,b.avatar,b.id as profile_id from auth_user as a left join sns_myprofile as b on a.id=b.user_id WHERE a.id=%s and a.is_active=1';
		$result = $this->query($sql, array(
				$userId
		));
		return $result->fetch_assoc();
	}
	public function getProfileByUserIds($userIds){
		$str = preg_replace('/(\d+)/i', '%s', implode(',',$userIds));
		$sql = 'select id,username from auth_user where id in('.$str.') and is_active=1';
		$result = $this->query($sql,$userIds);
		$usersInfo = array();
		while($result->fetch_assoc()){
			$usersInfo[$result->getData('id')]['UserName'] = $result->getData('username');
		}
		return $usersInfo;
	}
	public function addSnsProfile($model){
		$this->add($model);
	}

}